﻿using ORM.Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ORM.Base
{
    public class LocalTransactionManage
    {
        private static ConcurrentDictionary<string, LocalTransaction> TransactionDic = new ConcurrentDictionary<string, LocalTransaction>();

        public static void AddTransitionTask(string TaskID, DbTransaction Transition)
        {
            LocalTransaction LT = new LocalTransaction();
            LT.Transition = Transition;
            TransactionDic.TryAdd(TaskID, LT);
        }

        public static LocalTransaction GetTransitionTask(string TaskID)
        {
            LocalTransaction LT = null;
            TransactionDic.TryGetValue(TaskID, out LT);
            return LT;
           
        }

        public static bool ContainsTaskID(string TaskID)
        {
            return TransactionDic.ContainsKey(TaskID);
        }

        public static void RemoveTask(string TaskID)
        {
            if (ContainsTaskID(TaskID))
            {
                LocalTransaction LT = null;
                TransactionDic.TryRemove(TaskID, out LT);
            }
        }



    }
}
